<?php
require_once '../sub/init.php';
define('ZEAI2',dirname(__FILE__).DIRECTORY_SEPARATOR);
require_once 'chkUadm.php';
if(!in_array('excel_out',$QXARR))exit(noauth());
require_once ZEAI.'cache/udata.php';

header("Cache-control: private");
if ($submitok == "excelupdate") {
	$SQL = " AND kind<>4 ";
	$areaid = '';
	if (ifint($a1) && ifint($a2) && ifint($a3) && ifint($a4)){
		$areaid = $a1.','.$a2.','.$a3.','.$a4;
	}elseif(ifint($a1) && ifint($a2) && ifint($a3)){
		$areaid = $a1.','.$a2.','.$a3;
	}elseif(ifint($a1) && ifint($a2)){
		$areaid = $a1.','.$a2;
	}elseif(ifint($a1)){
		$areaid = $a1;
	}
	if (!empty($areaid))$SQL .= " AND areaid LIKE '%".$areaid."%' ";
	if (ifint($sex))$SQL     .= " AND sex=$sex ";
	if (ifint($age1))$SQL    .= " AND ( (YEAR(CURDATE())-YEAR(birthday)-(RIGHT(CURDATE(),5)<RIGHT(birthday,5))) >= $age1 ) ";
	if (ifint($age2))$SQL    .= " AND ( (YEAR(CURDATE())-YEAR(birthday)-(RIGHT(CURDATE(),5)<RIGHT(birthday,5))) <= $age2 ) ";
	if (ifint($pay))$SQL     .= " AND pay>=$pay ";
	if (ifint($edu))$SQL     .= " AND edu>=$edu ";
	if (ifint($nation))$SQL  .= " AND nation=$nation ";
	if (!empty($love)){
		$love = (is_array($love))?implode(',',$love):'';
		$SQL .= doinsql('love',$love);
	}
	if (!empty($child)){
		$child = (is_array($child))?implode(',',$child):'';
		$SQL .= doinsql('child',$child);
	}
	if (!empty($car)){
		$car = (is_array($car))?implode(',',$car):'';
		$SQL .= doinsql('car',$car);
	}
	if (!empty($house)){
		$house = (is_array($house))?implode(',',$house):'';
		$SQL .= doinsql('house',$house);
	}
	if (ifint($heigh1))$SQL .= " AND ( heigh >= $heigh1 ) ";
	if (ifint($heigh2))$SQL .= " AND ( heigh <= $heigh2 ) ";
	
	$nodatatext = '未填';
	$sDATE1 = strtotime($sDATE1.' 00:00:01');
	$sDATE2 = strtotime($sDATE2.' 23:59:59');
	$rt = $db->query("SELECT id,uname,nickname,sex,love,birthday,pay,job,heigh,weigh,edu,car,house,qq,weixin,mob,mob2,email,regtime,areatitle,area2title,truename,identitynum,bz,nation,crm_fromclue FROM ".__TBL_USER__." WHERE regtime >= '$sDATE1' AND regtime <= '$sDATE2' ".$SQL." ORDER BY id DESC");
	$total = $db->num_rows($rt);
	if($total>0){
		$content = "<meta http-equiv='Content-Type' content='text/html;charset=utf-8'><table border='1' cellpadding='0' cellspacing='0' bordercolor='#000000'><tr style='background:#FF6F6F;color:#fff'><td>UID</td><td>用户名</td><td>昵称</td><td>性别</td><td>出生年月</td><td>身高</td><td>体重</td><td>学历</td><td>车子</td><td>房子</td><td>婚姻状况</td><td>月收入</td><td>手机1</td><td>手机2</td><td>QQ</td><td>微信</td><td>邮箱</td><td>民族</td><td>地区</td><td>户籍</td><td>注册时间</td><td>真实姓名</td><td>身份证号</td><td>线索来源</td><td>备注</td></tr>";
		for($i=1;$i<=$total;$i++) {
			$rows = $db->fetch_array($rt,'name');
			if(!$rows) break;
			$uname = dataIO($rows['uname'],'out');
			$nickname = dataIO($rows['nickname'],'out');
			$sex      = $rows['sex'];
			$love     = $rows['love'];
			$birthday = $rows['birthday'];
			$pay   = $rows['pay'];
			$heigh = $rows['heigh'];
			$weigh = $rows['weigh'];
			$edu   = $rows['edu'];
			$car   = $rows['car'];
			$house = $rows['house'];
			$nation = $rows['nation'];
			$crm_fromclue = $rows['crm_fromclue'];
			$mob   = dataIO($rows['mob'],'out');
			$mob2   = dataIO($rows['mob2'],'out');
			$truename = dataIO($rows['truename'],'out');
			$identitynum = dataIO($rows['identitynum'],'out');
			$qq     = dataIO($rows['qq'],'out');
			$weixin = dataIO($rows['weixin'],'out');
			$email = dataIO($rows['email'],'out');
			$bz   = dataIO($rows['bz'],'out');
			$sex  = udata('sex',$sex);
			$love = udata('love',$love);
			$pay  = udata('pay',$pay);
			$edu  = udata('edu',$edu);
			$car  = udata('car',$car);
			$house = udata('house',$house);
			$nation = udata('nation',$nation);
			$crm_fromclue = udata('crm_fromclue',$crm_fromclue);
			$areatitle = dataIO($rows['areatitle'],'out');
			$area2title = dataIO($rows['area2title'],'out');
			$regtime = YmdHis($rows['regtime']);
			if ($birthday == '0000-00-00')$birthday = '';
			$identitynum = (empty($identitynum))?'':'['.$identitynum.']';
			$content.= "<tr><td>".$rows['id']."</td><td>".$uname."</td><td>".$nickname."</td><td>".$sex."</td><td>".$birthday."</td><td>".$heigh."</td><td>".$weigh."</td><td>".$edu."</td><td>".$car."</td><td>".$house."</td><td>".$love."</td><td>".$pay."</td><td>".$mob."</td><td>".$mob2."</td><td>".$qq."</td><td>".$weixin."</td><td>".$email."</td><td>".$nation."</td><td>".$areatitle."</td><td>".$area2title."</td><td>".$regtime."</td><td>".$truename."</td><td>".$identitynum."</td><td>".$crm_fromclue."</td><td>".$bz."</td></tr>";
		}
		$content.= '</table>';
		$filaname = date("YmdHis");
		header("Content-type:application/vnd.ms-excel;charset=utf-8");
		header("Content-Disposition:filename=".$filaname.".xls");
		echo $content;
		AddLog('用户【Excel数据导出】');
	} else {
		callmsg("暂无信息","-1");
	}
	exit;
}
function doinsql($F,$V) {
	if(!empty($V)){
		$Varr=explode(',',$V);
		if (count($Varr) >= 1 && is_array($Varr)){
			$newARR=array();
			foreach ($Varr as $v2) {if(ifint($v2))$newARR[]=$v2;}
			if(count($newARR)>0){
				$list = (is_array($newARR))?implode(',',$newARR):'';	
				$ZEAI_SQL = " AND $F IN ($list) ";
			}
		}
	}
	return $ZEAI_SQL;
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link href="css/main.css" rel="stylesheet" type="text/css">
<script src="<?php echo HOST;?>/res/www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo HOST;?>/cache/udata.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo HOST;?>/cache/areadata.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo HOST;?>/res/select4.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<style>
.SW,.SW_area,.SW_age{padding:0 3px}
.SW{width:100px}
.SW_area{width:100px;vertical-align:middle;padding:0}
.SW_age{width:75px;padding:0}
.SW_edu{width:110px;padding:0}
.SW_maxW{width:180px}
.RCW,.RCW2{display:inline-block}
.RCW li{width:80px}
.RCW2 li{width:120px}
.formline{height:10px}
.SW_checkbox,.SW_checkbox_x{display:inline-block;vertical-align:middle}
.SW_checkbox li,.SW_checkbox_x li{display:inline-block;vertical-align:middle;font-size:14px;color:#666}
.SW_checkbox li{width:100px;}
.textmiddle{font-size:14px}
.box{padding:50px 0}
.table td{font-size:14px}
</style>
</head>
<body>
<div class="box">
    <table class="table W90_ size2">
    <tr><td height="50" colspan="2" align="center"><b class="S18">用户资料Excel表导出</b><div class="C999"></div></td></tr>
    <form action="<?php echo SELF; ?>" method="post">
    <tr>
    <td width="150" height="20" align="right" bgcolor="#fafafa">筛选条件</td>
    <td height="20" align="left" bgcolor="#FFFFFF">
        <span class="textmiddle">性别</span> <script>nulltext='--';zeai_cn__CreateFormItem('select','sex','<?php echo $sex; ?>','class="size2 SW_edu"',sex_ARR);</script>　
        <div class="formline"></div>
        <span class="textmiddle">年龄</span> <script>nulltext='--';zeai_cn__CreateFormItem('select','age1','<?php echo $age1; ?>','class="size2 SW_edu"',age_ARR);</script> ～ <script>zeai_cn__CreateFormItem('select','age2','<?php echo $age2; ?>','class="size2 SW_edu"',age_ARR);</script>　　
        <div class="formline"></div>
        <span class="textmiddle">身高</span> <script>nulltext='--';zeai_cn__CreateFormItem('select','heigh1','<?php echo $heigh1; ?>','class="size2 SW_edu"',heigh_ARR);</script> ～ <script>zeai_cn__CreateFormItem('select','heigh2','<?php echo $heigh2; ?>','class="size2 SW_edu"',heigh_ARR);</script>　

        <div class="formline"></div>
        <span class="textmiddle">收入</span> <script>nulltext='--';zeai_cn__CreateFormItem('select','pay','<?php echo $pay; ?>','class="size2 SW_edu"',pay_ARR);</script>
        <div class="formline"></div>
        <span class="textmiddle">学历</span> <script>nulltext='--';zeai_cn__CreateFormItem('select','edu','<?php echo $edu; ?>','class="size2 SW_edu"',edu_ARR);</script>
        <div class="formline"></div>
        <span class="textmiddle">车子</span> <script>zeai_cn__CreateFormItem('checkbox','car','<?php echo $car; ?>','class="SW_checkbox_x"',car_ARR);</script>
        <div class="formline"></div>
        <span class="textmiddle">房子</span> <script>zeai_cn__CreateFormItem('checkbox','house','<?php echo $house; ?>','class="SW_checkbox_x"',house_ARR);</script>
        <div class="formline"></div>
        <span class="textmiddle">民族</span> <script>zeai_cn__CreateFormItem('select','nation','<?php echo $nation; ?>','class="SW_checkbox_x"',nation_ARR);</script>
        <div class="formline"></div>
        <span class="textmiddle">地区</span> <script>LevelMenu4('a1|a2|a3|a4|--|<?php echo $a1; ?>|<?php echo $a2; ?>|<?php echo $a3; ?>|<?php echo $a4; ?>|areaid|areatitle','class="size2 SW_area"');</script>　　
        <div class="formline"></div>
        <span class="textmiddle">婚状</span> <script>zeai_cn__CreateFormItem('checkbox','love','<?php echo $love; ?>','class=" SW_checkbox_x"',love_ARR);</script>
        <div class="formline"></div>
        <span class="textmiddle">子女</span> <script>zeai_cn__CreateFormItem('checkbox','child','<?php echo $child; ?>','class=" SW_checkbox_x"',child_ARR);</script>　　
    </td>
    </tr>
    <tr>
    <td width="150" align="right" bgcolor="#fafafa">注册时间</td>
    <td class="tdR">
    <input name="sDATE1" id="sDATE1" type="text"  class="input size2" value="<?php echo YmdHis(ADDTIME,'Ymd'); ?>" size="10" maxlength="10" autocomplete="off">
     <b>～</b> 
    <input name="sDATE2" id="sDATE2" type="text"  class="input size2" value="<?php echo YmdHis(ADDTIME,'Ymd'); ?>" size="10" maxlength="10" autocomplete="off">
    </td>
    </tr>
    <tr>
      <td width="150" bgcolor="#fafafa" class="tdL">&nbsp;</td>
      <td class="tdR">
      <button type="submit" class="btn size3"><i class="ico">&#xe63c;</i> 开始下载</button>
        <input name="submitok" type="hidden" value="excelupdate" /></td>
    </tr>
    </form>
    </table>
</div>
<script src="laydate/laydate.js"></script><script>lay('#version').html('-v'+ laydate.v);
laydate.render({elem: '#sDATE1'});
laydate.render({elem: '#sDATE2'});
</script>
<?php require_once 'bottomadm.php';?>